package main;
public class Daemon extends Thread {
	int delay;
	String username;
	String hostname;
	String password;
	int timeout;
	MySqlConnect mysql;
	Source s;

	public Daemon(Source s, MySqlConnect mysql) {
		this.s = s;
		this.mysql = mysql;
	}

	public void run() {
		while (true) {
			try {
				mysql.reconnect();
				long start = System.currentTimeMillis();
				s.importData(mysql);
				long end = System.currentTimeMillis();
				//System.out.println("wit: " + mysql.getLogFrequency());
				System.out.println("wait: "
						+ (mysql.getLogFrequency() - (end - start)));
				mysql.log();
				System.out.println(mysql.getLogFrequency());
				if (mysql.getLogFrequency() - (end - start) > 0)
					sleep(mysql.getLogFrequency() - (end - start));

			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}
	}

}
